//
//  HQRCDataSource.m
//  Trip
//
//  Created by ISU1 on 16/3/15.
//  Copyright © 2016年 HQ. All rights reserved.
//

#import "HQRCDataSource.h"
#import "RCDHttpTool.h"
static HQRCDataSource *_instance = nil;
@implementation HQRCDataSource
+ (HQRCDataSource *)shareInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[[self class] alloc] init];
    });
    return _instance;
}
- (void)syncFriendListWithUid:(NSString *)uid
                        token:(NSString *)token
                     keyWords:(NSString *)keyWords
                     pageSize:(NSInteger)pageSize
                      pageNum:(NSInteger)pageNum
                     complete:(void (^)(NSMutableArray *))completion {
    [RCDHTTPTOOL getFriendsWithUid:uid token:token keyWords:keyWords pageSize:pageSize pageNum:pageNum complete:^(NSMutableArray *result) {
         completion(result);
    }];
}

#pragma mark - RCIMUserInfoDataSource
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion {
    NSLog(@"getUserInfoWithUserId ----- %@", userId);
    
    if (userId == nil || [userId length] == 0 )
    {
        RCUserInfo *user = [RCUserInfo new];
        user.userId = userId;
        user.portraitUri = @"";
        user.name = @"";
        completion(user);
        return ;
    }
    if([userId isEqualToString:@"kefu114"])
    {
        RCUserInfo *user=[[RCUserInfo alloc]initWithUserId:@"kefu114" name:@"客服" portrait:@""];
        completion(user);
        return;
    }

    //开发者调自己的服务器接口根据userID异步请求数据
    [RCDHTTPTOOL getUserInfoByUid:[HQHttpManager getUserId]
                            token:[HQHttpManager getUserToken]
                        searchUid:userId
                       completion:^(RCUserInfo *user) {
        if (user) {
            completion(user);
        } else {
            RCUserInfo *user = [RCUserInfo new];
            user.userId = userId;
            user.portraitUri = @"";
            user.name = [NSString stringWithFormat:@"name%@", userId];
            completion(user);
        }
    }];
         
}
#pragma mark - GroupInfoFetcherDelegate
- (void)getGroupInfoWithGroupId:(NSString *)groupId completion:(void (^)(RCGroup *))completion {
    if (groupId.length == 0) {
        return;
    }
    [RCDHTTPTOOL getGroupInfoByUid:[HQHttpManager getUserId]
                             token:[HQHttpManager getUserToken]
                           groupId:groupId
                 successCompletion:^(RCGroup *group) {
                     completion(group);
        
    }];
}
#pragma mark RCIMGroupUserInfoDataSource
/**
 *  获取群组内的用户信息。
 *  如果群组内没有设置用户信息，请注意：
 1，不要调用别的接口返回全局用户信息，直接回调给我们nil就行，SDK会自己巧用用户信息提供者；
 2一定要调用completion(nil)，这样SDK才能继续往下操作。
 *
 *  @param groupId  群组ID.
 *  @param completion 获取完成调用的BLOCK.
 */
- (void)getUserInfoWithUserId:(NSString *)userId inGroup:(NSString *)groupId completion:(void (^)(RCUserInfo *))completion {
    
    completion(nil);
}
@end
